const compose = (...funcs) => {
    return funcs.reduce((a, b) => {
        return function (x) {
            return a(b(x))
        }
    })
}

const compose1 = (...funcs) => {
    if (funcs.length === 0) {
        return arg => arg
    }

    if (funcs.length === 1) {
        return funcs[0]
    }

    return funcs.reduce((a, b) => (...args) => a(b(...args)))
}


const multiply = (x) => x * 10;
const add = (y) => y + 10;
const minus = (z) => z - 2;
const calc = compose(minus, add, multiply)
const result = minus(add(multiply(10)))
console.log(calc(10), result)